<template>
  <div class="main">
    
      <div class="content">
        <el-row :gutter="10">
          <el-col :span="16">
                <div class="news-detail">
                    <h1 class="news-title">{{newsdetail.name}}</h1>
                    <p class="news-info" v-if="newsdetail.author">
                      <span>作者/来源：{{newsdetail.author}}</span>
                      <span>{{newsdetail.createtime.slice(0,11)}}</span>
                    </p>
                    <p class="news-info summary">
                      <i v-if="newsdetail.summary">[摘要]：{{newsdetail.summary}}</i>
                    </p>
                    <div class="contenthtml" v-if="newsdetail.contentList" style="width:100%;display:none" v-html="newsdetail.contentList.list[0]"></div>
                   <div class="contenthtml" style="width:100%;" v-for="(item,index) in newsdetail.contentList.list" :key="index"
                                 v-if="item && newsitem == index" v-html="item"></div>
                    <div class="end">
                      <!-- <p class="endline"></p> -->
                      <p class="end1">· END ·</p>
                      <p class="endmsg">此文章来源于网络，版权归原作者所有，文章仅代表作者观点，不代表平台观点。如有侵权，请及时联系我们进行删除。</p>

                    </div>
                    <div>
                      <!-- newslist -->
                      
                        <nuxt-link target="_blank"  v-for="(item,index) in newsdetail.tagName" :key="index" to="/newslist/touzi"><span class="tagitem">{{item}}</span></nuxt-link>
                      
                    </div>

                        <div class="bshare-custom icon-medium fenxiang" style="margin-bottom:20px;text-align: right;">
                          <div class="bsPromo bsPromo2"></div>
                            <span>分享：</span>
                            <a title="分享到微信" class="bshare-weixin" href="javascript:void(0);"></a>
                            <a title="分享到QQ空间" class="bshare-qzone"></a>
                            <a title="分享到QQ好友" class="bshare-qqim" href="javascript:void(0);"></a>
                            <a title="分享到新浪微博" class="bshare-sinaminiblog"></a>
                            <a title="分享到腾讯微博" class="bshare-qqmb"></a>
                          </div>
                        <script type="text/javascript" charset="utf-8" src="http://static.bshare.cn/b/buttonLite.js#style=-1&amp;uuid=&amp;pophcol=2&amp;lang=zh"></script>
                        <script type="text/javascript" charset="utf-8" src="http://static.bshare.cn/b/bshareC0.js"></script>
                  

                    <div v-if="newsdetail.contentList && newsdetail.contentList.count > 1" class="fenye">
                      <el-pagination
                        layout="prev, pager, next"
                        :page-size="1"
                        @current-change="handleCurrentChange"
                        :total="newsdetail.contentList.count">
                      </el-pagination>
                    </div>
                     <contactus3></contactus3>
                     <comment :commentdata='commentList'></comment>
                </div>
                <div class="xiangguang">
                    <div class="title">
                      <h1>相关文章</h1>
                    </div>
                    <ul>
                      <li v-for="(item,index) in newlist2" :key="index">
                        <nuxt-link target="_blank" :to="'/post/' + item.pid"><span class="newsname">{{item.name}}</span></nuxt-link>
                        <span>{{item.createtime.slice(0,11)}}</span>
                      </li>
                    </ul>
                </div>

          </el-col>
          <el-col :span="8">
                <contactus></contactus>
                <!-- <post1 :productlist="productlist"></post1> -->
                <detailnews :newslist="newlist"></detailnews>
           </el-col>
        </el-row>
      </div>
  </div>
</template>

<script>
import api from '../../../static/js/api.js'
import asyncApi from '../../../static/js/asyncApi.js'
import contactus from "../../../components/contactus";
import detailnews from "../../../components/detailnews";
import contactus3 from "../../../components/contactus3";
import post1 from "../../../components/post1";
import comment from "../../../components/comment";



export default {
  scrollToTop: true,
  data(){
    return{
        newsitem:0,
        newlist2:[]
    }
  },
  components: {
    contactus,
    detailnews,
    contactus3,
    post1,
    comment
  },
  methods:{
    handleCurrentChange(val){
        this.newsitem = val-1
        this.gotoTop()
    },
    menu() {
        this.scroll = document.documentElement.scrollTop || document.body.scrollTop;
          if(this.scroll >= 560){
            this.isshowfixednav = true
          }else{
             this.isshowfixednav = false
          }
    },
    gotoTop(){
       var scrollToptimer = setInterval(function () {
            var top = document.body.scrollTop || document.documentElement.scrollTop;
            var speed = top / 4;
            if (document.body.scrollTop!=0) {
                document.body.scrollTop -= speed;
            }else {
                document.documentElement.scrollTop -= speed;
            }
            if (top <= 30) {
                clearInterval(scrollToptimer);
            }
        }, 30); 
    },
    getXiangguan(tap){
      api.getTagPost({tagName: tap ,page: "1",pageSize: "4",orderBy:"createtime",orderByType:"desc"}).then((res)=>{
             if(res.code == 1){
               this.newlist2 = res.data.list
            }else{
           
            }
        })
    
    }
  },
  mounted(){      
          window.addEventListener('scroll', this.menu);
          this.getXiangguan(this.newsdetail.tagName[0])
  },
  async asyncData (context) {
    var id = parseInt(context.params.id);
    let [data1,data2,data3,data4] = await Promise.all([
        asyncApi.asyncGetCategoryPost({categoryName: '投资策略' ,page: "1",pageSize: "4",orderBy:"createtime",orderByType:"desc"}),
        asyncApi.asyncgetPostDetail({id:id}),
        asyncApi.asyncgetProduct({page:"1",pageSize:"5"}),
        asyncApi.getNewsLists({postId:id})
    ])
    return {
      newlist:data1.data.data.list,
      newsdetail:data2.data.data,
      productlist:data3.data.data.list,
      commentList:data4.data.data
    }
 },
 head () {
    return {
      title: this.newsdetail.name+ "__天沁财富",
        meta: [
         { hid:"keywords",name: 'keywords', content: this.newsdetail.name + "_天沁财富"},
         { hid:"description",name: 'description', content: this.newsdetail.summary}
      ]
     }
  }
};
</script>

<style scoped>
.end{
  margin: 30px;
} 
.end1{
  text-align: center; 
  color: #666;

}
.endmsg{
  width: 500px;
  font-size: 14px;
  text-align: center;
  margin: 20px auto;
  color: #666;
  line-height: 30px;
}
.endline{
  width: 90%;
  margin: 0 auto;
  height: 1px;
  background: #e6e6e6;
}
.endcont{
  font-size: 16px;
  text-align: center;
  height: 20px;
  line-height: 20px;
  margin-top: 10px;
}
.bshareDiv img{
  height: 30px;
  width: 30px;
  vertical-align: middle;
}
.bshareDiv{
  height: 30px;
  line-height: 30px;
}
.tagitem{
  display: inline-block;
  height: 26px;
  text-align: center;
  padding: 0 10px;
  line-height: 26px;
  background: #cd9c54;
  color: white;
  font-size: 14px;
  margin-right: 20px;
}
.fenye{
  text-align: center;
} 
.xiangguang{
  background: white;
  padding: 20px;
}
.xiangguang .title{
  border-bottom: 1px solid #cd9c54;
}
.newsname{
  display: inline-block;
  width: 600px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.main .xiangguang h1{
  font-size: 16px;
  width: 150px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  color: white;
  background: #cd9c54;
}
.xiangguang ul{
  padding:  0 30px;
}
.xiangguang ul li{
  display: flex;
  justify-content: space-between;
  height: 50px;
  line-height: 50px;
  font-size: 14px;
  color: #333;
}
.productDetali{
  height: 100px;
  border-bottom:1px solid #ccc; 
}
.productDetali p{
  color: #666;
}
.productDetali i{
  color: #b41d24;
}
.productDetali p span:nth-child(2){
  margin-left: 30px;
}
.productDetali h2{
  height: 50px;
  line-height: 50px;
  font-size: 18px;
  color: #333;
  font-weight: bolder;
  margin-top: 20px;
}
.news-detail{
  padding: 20px;
  background: white;
}
.news-title{
  text-align: center;
}
.news-info{
  margin: 20px 0 0 0;
  text-align: left;
  color: #666;
}
.news-info span:nth-child(2){
  margin-left: 30px;
}
.summary{
  background: #f5f5f5;  
  padding: 10px;
    margin-bottom: 20px;
  
}
.news-info i{
    width: 100%;
    display: block;
    line-height: 24px;
    max-height: 72px;
    overflow: hidden;
    box-sizing: border-box;
    text-align: left;
}
.contenthtml p{
  color: red !important;
}
.newsBox{
  background: white;
  padding: 20px;
  margin-top: 10px;
}
.newsBox h1 {
  color: #cd9c54 !important;
  font-size: 20px !important;
  height: 30px;
  line-height: 30px;
  border-bottom:1px solid #ccc; 
}

.main {
  width: 1200px;
  margin: 10px auto;
}
.main h1 {
  font-size: 20px;
  line-height: 30px;
  color: black;
  font-weight: normal;
}


</style>
